<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@ include file="/include/taglibs.jsp"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page isELIgnored="false" %>
<head>
  <title>TOPIC管理</title>
  <link rel="stylesheet" href="${ctx}/assets/admin/LingUI/css/ui.jqgrid.css" />
</head>

<div class="row">
  <div class="col-xs-12">
    <button class="btn btn-sm btn-success fa fa-plus-circle" type="button" onclick="add()">添加</button>
    <div class="b_grid_line  col-lg-12"></div>
    <table id="topic_list_table" class="grid-table"></table> 	<%--jqgrid数据表格 --%>
  </div>
</div>
<script type="text/javascript">
  var scripts = [null,
    "${ctx}/assets/admin/LingUI/js/jqGrid/jquery.jqGrid.js",
    "${ctx}/assets/admin/LingUI/js/jqGrid/i18n/grid.locale-cn.js",
    "${ctx}/assets/admin/LingUI/js/control.js",
    "${ctx}/assets/admin/LingUI/js/jsutil/js/jquery.filterSearch.js",   //筛选搜索
    null];
  var _grid_id = "#topic_list_table";	//表格 选择器
  ace.load_ajax_scripts(scripts, function() {
    //调整以适应页面大小  其中 $(".page-content") 为jqgrid的父级容器
    $(window).off('resize.jqGrid').on('resize.jqGrid', function () {
      setTimeout(function(){
        $(_grid_id).jqGrid("setGridWidth",$(".page-content").width());
        $(".ui-jqgrid-bdiv").width($(".page-content").width()+1);
      },50);
    });
    jQuery(_grid_id).jqGrid({
      mtype : "POST",
      url: "${ctx}/${frameworkPath}/mq/topic/list",
      colNames:['TOPIC名称','操作'],
      colModel:[
        {name:'topicName',index:'topicName', width:0,  editable: true},
        {name:'action',index:'', width:100, fixed:false, sortable:false,align:'center', formatter:
                function(cellvalue, options, rowObject) {
                  var s='<div class=" action-buttons">'
                  s=s+  '<button class="btn btn-sm btn-info" type="button" onclick="state('+cellvalue+')">状态</button>&nbsp;&nbsp;';
                  s=s+  '<button class="btn btn-sm btn-info" type="button">路由</button>&nbsp;&nbsp;';
                  s=s+  '<button class="btn btn-sm btn-info" type="button">更新</button>&nbsp;&nbsp;';
                  s=s+  '<button class="btn btn-sm btn-danger" type="button">删除</button>&nbsp;&nbsp;';
                  return s+'</div>';}
        }
      ]
    });
  });

  //编辑数据
  function state(topicName){
    lui.open({
      title: '查看状态',
      content: "${ctx}/${frameworkPath}/module/edit?id="+id,
      area: ['600px', '300px'],
      yes: function(index, layero){
        var iframeWin = $(layero).find("iframe")[0].contentWindow;
        var retObj = iframeWin.formValid();
        if(retObj.text){
          lui.info(retObj.text);
          if(retObj.state){
            layer.close(index);
            jQuery(_grid_id).trigger("reloadGrid");
          }
        }
      }
    });
  }
</script>